package com.song.shop.test;

/**
 * @author Song Yinghui
 * @date 2019/8/8
 * @Version 1.0
 *
 * 求数组 num 中是否存在一组数字相加为目标数K
 */
public class test18 {


    private static int k = 10 ;

    private static int[] num  = new int[]{1,2,6,7,2,9,10};


    static Boolean flag = false;

    public void dfs(int curr, int res){

        if (res > k){
            return;
        }
        if (res == k){
            flag = true;
            return;
        }
        if (flag){
            return;
        }
        if (curr == num.length){
            return;
        }
        dfs(curr +1,res + num[curr]);
        dfs(curr+1,res);
    }

    public static void main(String[] args) {
        new test18().dfs(0,0);
        if (flag){
            System.out.println("yes");
        }else {
            System.out.println("No");
        }
    }
}
